(function() {
  var active, b1, b2, button1, button2, button3, center, clicked, hbox, label, left, local_offset, local_plugin, offset, plugin, plugins, proxy, text, _i, _len;
  tree.using('tree.ui');
  tree.using('tree.ressources');
  tree.ui.Window.set_title(strings.get_string('title'));
  hbox = new tree.ui.HBox;
  button1 = new tree.ui.Button('button1');
  button2 = new tree.ui.Button('button2');
  button3 = new tree.ui.Button('button3');
  left = new tree.ui.VBox;
  left.add(button1);
  left.add(button2);
  left.add(button3);
  left.set_style('width', 'auto');
  left.set_style('height', 'auto');
  hbox.add(left);
  center = new tree.ui.Table;
  hbox.add(center);
  center.set_style('width', 'auto');
  center.set_style('height', 'auto');
  proxy = new tree.io.rpc.JSON_Proxy('/rpc');
  plugins = proxy.call_method('list_bundles', []);
  offset = 0;
  for (_i = 0, _len = plugins.length; _i < _len; _i++) {
    plugin = plugins[_i];
    console.log(offset);
    label = new tree.ui.Label(plugin);
    b1 = new tree.ui.Button(strings.get_string('show_deps'));
    local_offset = offset;
    local_plugin = plugin;
    clicked = function(widget, event, args) {
      var build_graph, graph;
      if (widget.treeview != null) {
        widget.set_text(strings.get_string('show_deps'));
        center.remove(widget.treeview);
        widget.treeview = null;
        return;
      }
      widget.set_text(strings.get_string('hide_deps'));
      local_offset = args[0], local_plugin = args[1];
      widget.treeview = new tree.ui.TreeView;
      build_graph = function(plugin) {
        var dep, deps, name, ret, type, val, _j, _len2;
        ret = {};
        deps = proxy.call_method('get_dependencies', [plugin]);
        for (_j = 0, _len2 = deps.length; _j < _len2; _j++) {
          dep = deps[_j];
          type = dep[0], name = dep[1];
          val = null;
          if (type === 'bundle') {
            val = build_graph(name);
            if ((Object.keys(val)).length === 0) val = null;
          }
          ret[type + ': ' + name] = val;
        }
        return ret;
      };
      graph = build_graph(local_plugin);
      widget.treeview.set_data(graph);
      return center.add(widget.treeview, 3, local_offset);
    };
    b1.connect('clicked', clicked, [local_offset, local_plugin]);
    text = '';
    active = proxy.call_method('is_bundle_active', [plugin]);
    if (active === true) {
      text = 'Stop';
    } else {
      text = 'Activate';
    }
    b2 = new tree.ui.Button(text);
    center.add(label, 0, offset);
    center.add(b1, 1, offset);
    center.add(b2, 2, offset);
    offset += 1;
  }
  tree.ui.Window.show(hbox);
}).call(this);
